/* Copyright (c) 2004-2022 peigen.info. All rights reserved. */

package info.peigen.hotpot.common.core.domain;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import info.peigen.hotpot.common.core.annotation.Comment;
import info.peigen.hotpot.common.core.util.ValidationUtil;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

import java.util.Date;

/**
 * <b>(DomainObject)</b>
 * 领域对象
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/7/28
 */
@SuppressWarnings("AlibabaAbstractClassShouldStartWithAbstractNaming")
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public abstract class DomainObject implements Domain {
    @Comment(value = "默认Id,对应 AbstractCreateTimeEntity.id")
    Integer id;

    @Comment(value = "合作伙伴ID")
    String partnerId;

    @Comment(value = "逻辑删除标识，-1")
    Integer enable;

    @Comment(value = "领域对象创建时间")
    @NotNull
    @Builder.Default
    Date createTime = DateUtil.date();

    @Comment(value = "领域对象更新时间")
    @NotNull
    @Builder.Default
    Date updateTime = DateUtil.date();

    @Override
    public void check() {
        ValidationUtil.validateParams(this);
    }

    @Override
    public String toString() {
        check();
        return JSON.toJSONString(this, JSONWriter.Feature.PrettyFormat);
    }
}